package com.eastfair.home.service.impl;

import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.context.StaticContextUtil;
import com.eastfair.home.service.HomeHomeServiceOrderService;
import com.eastfair.home.service.HomeServiceProviderService;
import com.eastfair.messagecenter.util.SendMsgUtil;
import com.eastfair.venueservice.dto.ServiceOrderDTO;
import com.eastfair.venueservice.vo.ServiceProviderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 主场，搭建商 服务订单 service.
 *
 * @author dqq
 * @date 2022 /11/11
 */
@Service
@Slf4j
public class HomeHomeServiceOrderServiceImpl implements HomeHomeServiceOrderService {

    @Resource
    private HomeServiceProviderService homeServiceProviderService;

    @Resource
    private SendMsgUtil sendMsgUtil;

    @Override
    public boolean sendConfigPayeeInnerMsg(ServiceOrderDTO serviceOrder) {
        log.info("sendConfigPayeeInnerMsg - 发送配置收款商户的站内信, serviceOrder={}", serviceOrder);
        Integer isManageExpense = serviceOrder.getIsManageExpense();
        String orderType;
        if (isManageExpense == BusinessConstant.YES) {
            orderType = "管理费订单";
        } else {
            orderType = "服务订单";
        }
        ServiceProviderVO home = homeServiceProviderService.getHomeByExhibitionIdAndSpaceCode(serviceOrder.getExhibitionManageId(), serviceOrder.getSpaceCode());
        if (home == null) {
            log.warn("无法发动站内信，未找到主场服务商");
            return false;
        }
        String content = String.format("主场【%s】，您好，%s已生成，如需收款请到财务系统配置收款账号！", home.getCompanyName(), orderType);
        sendMsgUtil.sendInnerMsgByTeamId(content, home.getId(), StaticContextUtil.getProjectSystemScene());
        return true;
    }
}